home *** CD-ROM | disk | FTP | other *** search
- Path: camelot.ccs.neu.edu!jason
- From: jason@ccs.neu.edu (Jason Leatherman)
- Newsgroups: comp.lang.c
- Subject: Float calculations
- Date: 1 Feb 1996 17:22:23 GMT
- Organization: College of Computer Science, Northeastern University.
- Message-ID: <4eqssf$d9q@camelot.ccs.neu.edu>
- NNTP-Posting-Host: alumni.ccs.neu.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
-
- Hi,
-
- Check out the results I get when running this simple program on a
- Sparc/UNIX system, compiled with gcc:
-
- #include <stdio.h>
-
- void main()
- {
- float a, b;
-
- printf("%0.10f %0.10f %0.10f\n", 99974.0, 50.0, 99974.0/50.0);
-
- a = 99974.0;
- b = 50.0;
- printf("%0.10f %0.10f %0.10f\n", a, b, a/b);
- }
-
- The output is:
- 99974.0000000000 50.0000000000 1999.4800000000
- 99974.0000000000 50.0000000000 1999.4799804688
-
- Why do the divisions produce different results? This is probably some
- simple thing that I've forgotten, but I haven't figured it out yet. Does
- anyone know? Note that compiling with the -ffloat-store flag didn't make
- a difference.
- Thanks for any help,
-
- Jason
-